package com.zycfc.zsf.boot.util.math;

import java.math.*;
import com.zycfc.zsf.boot.util.text.*;

public class BigDecimalUtils
{
    public static BigDecimal add(final String a1, final String a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = new BigDecimal(a1);
        final BigDecimal b2 = new BigDecimal(a2);
        return b1.add(b2);
    }
    
    public static BigDecimal add(final Integer a1, final Integer a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.add(b2);
    }
    
    public static BigDecimal add(final Long a1, final Long a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.add(b2);
    }
    
    public static BigDecimal add(final Float a1, final Float a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.add(b2);
    }
    
    public static BigDecimal add(final Double a1, final Double a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.add(b2);
    }
    
    public static BigDecimal subtract(final String a1, final String a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = new BigDecimal(a1);
        final BigDecimal b2 = new BigDecimal(a2);
        return b1.subtract(b2);
    }
    
    public static BigDecimal subtract(final Integer a1, final Integer a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.subtract(b2);
    }
    
    public static BigDecimal subtract(final Long a1, final Long a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.subtract(b2);
    }
    
    public static BigDecimal subtract(final Float a1, final Float a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.subtract(b2);
    }
    
    public static BigDecimal subtract(final Double a1, final Double a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.subtract(b2);
    }
    
    public static BigDecimal multiply(final String a1, final String a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = new BigDecimal(a1);
        final BigDecimal b2 = new BigDecimal(a2);
        return b1.multiply(b2);
    }
    
    public static BigDecimal multiply(final Integer a1, final Integer a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.multiply(b2);
    }
    
    public static BigDecimal multiply(final Long a1, final Long a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.multiply(b2);
    }
    
    public static BigDecimal multiply(final Float a1, final Float a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.multiply(b2);
    }
    
    public static BigDecimal multiply(final Double a1, final Double a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.multiply(b2);
    }
    
    public static BigDecimal divide(final Integer a1, final Integer a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.divide(b2);
    }
    
    public static BigDecimal divide(final Long a1, final Long a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.divide(b2);
    }
    
    public static BigDecimal divide(final Float a1, final Float a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.divide(b2);
    }
    
    public static BigDecimal divide(final Double a1, final Double a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        final BigDecimal b1 = BigDecimal.valueOf(a1);
        final BigDecimal b2 = BigDecimal.valueOf(a2);
        return b1.divide(b2);
    }
    
    public static boolean equals(final BigDecimal a1, final BigDecimal a2) {
        if (StringUtils.isEmpty(a1) || StringUtils.isEmpty(a1)) {
            throw new NullPointerException("\u8f93\u5165\u53c2\u6570\u4e3a\u7a7a");
        }
        return a1.compareTo(a2) == 0;
    }
    
    public static void main(final String[] args) {
        final BigDecimal amount1 = new BigDecimal("0.06");
        final BigDecimal amount2 = new BigDecimal(0.06);
        final BigDecimal amount3 = new BigDecimal("0.06");
        System.out.println(amount1);
        System.out.println(amount2);
        System.out.println(amount1.equals(amount3));
        System.out.println(amount1.compareTo(amount3));
    }
}
